const multer = require('multer');
const { v4: uuidv4 } = require('uuid');
const path = require('path');
let storage = null

storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/');
    },
    filename: function (req, file, cb) {
        // 生成UUID并将其转换为字符串
        const uuidString = uuidv4().toString();
        // 如果字段名不存在，使用默认值 "file"
        const fieldName = file.fieldname || "file";
        cb(null, `${uuidString}-${fieldName}-${new Date().getTime()}${path.extname(file.originalname)}`);
    }
});

const upload = multer({ storage: storage });

module.exports = upload